package top.sdwu_top.kbase.controller;



import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.hibernate.validator.constraints.CodePointLength;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import top.sdwu_top.kbase.common.annocation.CurrentUser;
import top.sdwu_top.kbase.common.model.Wrapper;
import top.sdwu_top.kbase.entity.KbaseAuthUser;
import top.sdwu_top.kbase.entity.KbaseFileComment;
import top.sdwu_top.kbase.service.IKbaseFileCommentService;
import top.sdwu_top.kbase.vo.KbaseFileCommentVo;

/**
 * <p>
 * 文件评论 前端控制器
 * </p>
 *
 * @author zhipeng.duan@nvr-china.com
 * @since 2020-02-20
 */
@RestController
@RequestMapping("api/file-comment")
public class KbaseFileCommentController {

    @Autowired
    IKbaseFileCommentService commentService;

    @PostMapping("page")
    public Wrapper<Page<KbaseFileComment>> page(@CurrentUser KbaseAuthUser user, @RequestBody KbaseFileCommentVo commentVo) {
        return Wrapper.ok(commentService.page(user, commentVo));
    }

    @PostMapping
    public Wrapper<String> create(KbaseFileComment comment) {
        if (commentService.create(comment)) {
            return Wrapper.ok("评论成功");
        }
        return Wrapper.ok("评论失败");
    }


    @PutMapping
    public Wrapper<String> update(KbaseFileComment comment) {
        if (commentService.update(comment)) {
            return Wrapper.ok("评论修改成功");
        }
        return Wrapper.ok("评论修改失败");
    }


    @DeleteMapping("{id}")
    public Wrapper<String> delete(@PathVariable("id") String id) {
        if (commentService.delete(id)) {
            return Wrapper.ok("删除成功");
        }
        return Wrapper.ok("删除失败");
    }


}

